<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\models\Poststatus;
use yii\helpers\ArrayHelper;





/* @var $this yii\web\View */
/* @var $model common\models\Post */
/* @var $form yii\widgets\ActiveForm */
?>

<div class="post-form">

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'content')->textarea(['rows' => 6]) ?>

    <?= $form->field($model, 'tags')->textarea(['rows' => 6]) ?>


<?php
    //第一种方法
//    $psObjs = Poststatus::find()->all();
//    $allStatus =ArrayHelper::map($psObjs,'id','name');
//第二种方法
//$psAarray = Yii::$app->db->createCommand('select id,name from poststatus')->queryAll();
//$allStatus = ArrayHelper::map($psAarray,'id','name');
//$allStatus = \yii\helpers\ArrayHelper::map($psAarray,'id','name');
//第三种方法  查询构造器
//$allStatus = (new  \yii\db\Query())->select(['name','id'])
//                                  ->from('poststatus')
//                                    ->indexBy('id')
//                                  ->column();
//第四种

$allStatus = Poststatus::find()
    ->select(['name','id'])
    ->from('poststatus')
    ->orderBy('position')
    ->indexBy('id')
    ->column();



//echo"<pre>";
//print_r($allStatus);
//echo "</pre>";
//exit(0);

?>


    <?=$form->field($model,'status')
        ->dropDownList($allStatus,['prompt'=>'请选择状态']);?>

    <?=$form->field($model,'author_id')
        ->dropDownList(\common\models\Adminuser::find()
            ->select(['nickname','id'])
            ->from('adminuser')
            ->indexBy('id')
            ->column(),['prompt'=>'请选择状态']);?>

    <div class="form-group">
        <?= Html::submitButton($model->isNewRecord ? '新增' : '修改', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
    </div>

    <?php ActiveForm::end(); ?>

</div>
